// components/todolist/todolist-insert.ts
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    majorIndex: "0",
    majors: ["JAVA","WEB"],
    formData: {
      major: "JAVA",
      sex: "男"
    },
    id: 100,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleMajorChange(v:any) {
      const major = this.data.majors[v.detail.value];
      const formData = this.data.formData;
      formData.major = major;
      // 微信小程序，需要使用setData来人工改变数据触发渲染
      this.setData({formData});
      console.log("v.detail.value = ",v.detail.value);
    },
    handleSexChange(v:WechatMiniprogram.RadioGroupChange) {
      const sex = v.detail.value;
      this.data.formData.sex = sex;
    },
    handleSubmit() {
      // 子传父也需要触发自定义事件
      this.triggerEvent("submit",{...this.data.formData,id: this.data.id ++})
    }
  }
})
